#include "aviones.h"
#include "globals.h"
#include <stdio.h>


void report_and_wait(avion_t this){
	

	pthread_mutex_lock(&mutex);
	ready_count++;
	pthread_cond_signal(&cond);
	pthread_cond_wait(&this->cond,&mutex);
	pthread_mutex_unlock(&mutex);

}



void* avion(void* avion){
	
	avion_t this=(avion_t)avion;
	
	this->distancia=0;
	pthread_cond_init(&this->cond, NULL); 

	report_and_wait(this);
	while(!the_end){
		if(this->distancia==0){
			if(the_end)
				break;
			libres[cant_libres]=this;
			cant_libres++;
		}
		if(the_end)
			break;
		report_and_wait(this);
		if(the_end)
			break;
		min_distance=this->distancia<min_distance? this->distancia: min_distance;
		if(the_end)
			break;
		report_and_wait(this);
		if(the_end)
			break;
		this->distancia-=generalMinDistance;
	}
	
}
